//
//  VehicleMaintenanceDetailHeader.m
//  阿帕
//
//  Created 阿帕 on 2020/1/5.
//  Copyright © 2020 GCY. All rights reserved.
//

#define item_height 40

#import "VehicleMaintenanceDetailHeader.h"
#import "UIView+Tap.h"

@interface VehicleMaintenanceDetailHeader ()

@property (strong, nonatomic)UILabel *statusLabel;
@property (strong, nonatomic)UILabel *shenPiTextLabel;
@property (strong, nonatomic)UIView *bLine;

@end

@implementation VehicleMaintenanceDetailHeader

#pragma mark - Intial
- (instancetype)initWithFrame:(CGRect)frame {
    
    self = [super initWithFrame:frame];
    if (self) {
        
        [self setUpUI];
    }
    return self;
}

- (void)setUpUI {
    
    //    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 0, 200, 40)];
    //    titleLabel.font = font(16);
    //    titleLabel.textColor = Dark_TextColor;
    //    titleLabel.text = @"维修申请";
    //    [self addSubview:titleLabel];
    //
    ////    NSArray *titlesArr = @[@"申请内容", @"申请详情", @"车牌号码"]; 40 + 40 + 165
    //
    //    float valueMaxWidth = ScreenW-70-40;
    //
    //    ///申请内容
    //    UILabel *contentTextLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, titleLabel.cy_bottom, 70, item_height)];
    //    contentTextLabel.font = font(14);
    //    contentTextLabel.textColor = Light_TextColor;
    //    contentTextLabel.text = @"申请内容";
    //    contentTextLabel.adjustsFontSizeToFitWidth = YES;
    //    [self addSubview:contentTextLabel];
    //
    //    UILabel *contentValueLabel = [[UILabel alloc] initWithFrame:CGRectMake(contentTextLabel.cy_right+10, contentTextLabel.cy_y, valueMaxWidth, _contentHeight)];
    //    contentValueLabel.tag = 100;
    //    contentValueLabel.font = font(14);
    //    contentValueLabel.textColor = Dark_TextColor;
    //    contentValueLabel.textAlignment = NSTextAlignmentRight;
    //    contentValueLabel.text = @"-";
    //    [self addSubview:contentValueLabel];
    //
    //
    //    ///申请详情
    //    UILabel *detailTextLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, contentValueLabel.cy_bottom, 70, item_height)];
    //    detailTextLabel.font = font(14);
    //    detailTextLabel.textColor = Light_TextColor;
    //    detailTextLabel.text = @"申请详情";
    //    detailTextLabel.adjustsFontSizeToFitWidth = YES;
    //    [self addSubview:detailTextLabel];
    //
    //    UILabel *detailValueLabel = [[UILabel alloc] initWithFrame:CGRectMake(detailTextLabel.cy_right+10, detailTextLabel.cy_y, valueMaxWidth, _detailHeight)];
    //    detailValueLabel.tag = 101;
    //    detailValueLabel.font = font(14);
    //    detailValueLabel.textColor = Dark_TextColor;
    //    detailValueLabel.textAlignment = NSTextAlignmentRight;
    //    detailValueLabel.text = @"-";
    //    [self addSubview:detailValueLabel];
    //
    //    ///车牌号
    //    UILabel *carNumTextLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, detailValueLabel.cy_bottom, 70, item_height)];
    //    carNumTextLabel.font = font(14);
    //    carNumTextLabel.textColor = Light_TextColor;
    //    carNumTextLabel.text = @"申请详情";
    //    carNumTextLabel.adjustsFontSizeToFitWidth = YES;
    //    [self addSubview:carNumTextLabel];
    //
    //    UILabel *carNumValueLabel = [[UILabel alloc] initWithFrame:CGRectMake(carNumTextLabel.cy_right+10, carNumTextLabel.cy_y, valueMaxWidth, item_height)];
    //    carNumValueLabel.tag = 102;
    //    carNumValueLabel.font = font(14);
    //    carNumValueLabel.textColor = Dark_TextColor;
    //    carNumValueLabel.textAlignment = NSTextAlignmentRight;
    //    carNumValueLabel.text = @"-";
    //    [self addSubview:carNumValueLabel];
    //
    ////    for (int i=0; i<titlesArr.count; i++) {
    ////
    ////        UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(0, titleLabel.cy_bottom + 40*i, ScreenW, 40)];
    ////        [self addSubview:bgView];
    ////
    ////
    ////        UILabel *textLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 0, 70, bgView.cy_height)];
    ////        textLabel.font = font(14);
    ////        textLabel.textColor = Light_TextColor;
    ////        textLabel.text = titlesArr[i];
    ////        textLabel.adjustsFontSizeToFitWidth = YES;
    ////        [bgView addSubview:textLabel];
    ////
    ////        UILabel *valueLabel = [[UILabel alloc] initWithFrame:CGRectMake(textLabel.cy_right+10, 0, ScreenW-70-40, bgView.cy_height)];
    ////        valueLabel.tag = 100 + i;
    ////        valueLabel.font = font(14);
    ////        valueLabel.textColor = Dark_TextColor;
    ////        valueLabel.textAlignment = NSTextAlignmentRight;
    ////        valueLabel.text = @"-";
    ////        [bgView addSubview:valueLabel];
    ////
    ////        UIView *line = [[UIView alloc] initWithFrame:CGRectMake(15, 39, ScreenW-30, 1)];
    ////        line.backgroundColor = BackgroundColor;
    ////        [bgView addSubview:line];
    ////    }
    //
    //
    //
    //    //图片区域
    //    UIView *imgBgView = [[UIView alloc] initWithFrame:CGRectMake(0, carNumValueLabel.cy_bottom, ScreenW, 40 + 75)];
    //    imgBgView.tag = 150;
    //    [self addSubview:imgBgView];
    //
    //    UILabel *imgTitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 0, 200, 40)];
    //    imgTitleLabel.font = font(14);
    //    imgTitleLabel.textColor = Dark_TextColor;
    //    imgTitleLabel.text = @"相关图片：";
    //    [imgBgView addSubview:imgTitleLabel];
    //
    //
    //    //维修状态
    //    _statusLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, imgBgView.cy_bottom, 200, 40)];
    //    _statusLabel.font = font(14);
    //    _statusLabel.textColor = Green_Color;
    //    _statusLabel.text = @"审核状态";
    //    [self addSubview:_statusLabel];
    //
    //    _bLine = [[UIView alloc] initWithFrame:CGRectMake(0, _statusLabel.cy_bottom, ScreenW, 10)];
    //    _bLine.backgroundColor = BackgroundColor;
    //    [self addSubview:_bLine];
    
    
    
    
#pragma mark -
    _shenPiTextLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, _bLine.cy_bottom, 200, 40)];
    _shenPiTextLabel.font = font(16);
    _shenPiTextLabel.textColor = Dark_TextColor;
    _shenPiTextLabel.text = @"审批详情";
    _shenPiTextLabel.hidden = YES;
    [self addSubview:_shenPiTextLabel];
}

- (void)setDetailDic:(NSDictionary *)detailDic {
    
    _detailDic = detailDic;
    
    float valueMaxWidth = ScreenW-70-40;
    
    CGSize contentSize = [DCSpeedy dc_calculateTextSizeWithText:[NSString nullToString:detailDic[@"title"]] WithTextFont:14 WithMaxW:valueMaxWidth];
    CGSize detailSize = [DCSpeedy dc_calculateTextSizeWithText:[NSString nullToString:detailDic[@"details"]] WithTextFont:14 WithMaxW:valueMaxWidth];
    
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 0, 200, 40)];
    titleLabel.font = font(16);
    titleLabel.textColor = Dark_TextColor;
    titleLabel.text = @"维修申请";
    [self addSubview:titleLabel];
    
    //    NSArray *titlesArr = @[@"申请内容", @"申请详情", @"车牌号码"]; 40 + 40 + 165
    
    ///申请内容
    UILabel *contentTextLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, titleLabel.cy_bottom, 70, item_height)];
    contentTextLabel.font = font(14);
    contentTextLabel.textColor = Light_TextColor;
    contentTextLabel.text = @"申请内容";
    contentTextLabel.adjustsFontSizeToFitWidth = YES;
    [self addSubview:contentTextLabel];
    
    UILabel *contentValueLabel = [[UILabel alloc] initWithFrame:CGRectMake(contentTextLabel.cy_right+10, contentTextLabel.cy_y, valueMaxWidth, contentSize.height)];
    if (contentSize.height<40.0) {
        contentValueLabel.height = 40;
    } else {
        contentValueLabel.height += 20;
    }
    contentValueLabel.font = font(14);
    contentValueLabel.textColor = Dark_TextColor;
    contentValueLabel.textAlignment = NSTextAlignmentRight;
    contentValueLabel.text = [NSString nullToString:detailDic[@"title"]];
    contentValueLabel.numberOfLines = 0;
    [self addSubview:contentValueLabel];
    
    UIView *line = [[UIView alloc] initWithFrame:CGRectMake(15, contentValueLabel.cy_bottom-1, ScreenW-30, 1)];
    line.backgroundColor = BackgroundColor;
    [self addSubview:line];
    
    
    ///申请详情
    UILabel *detailTextLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, contentValueLabel.cy_bottom, 70, item_height)];
    detailTextLabel.font = font(14);
    detailTextLabel.textColor = Light_TextColor;
    detailTextLabel.text = @"申请详情";
    detailTextLabel.adjustsFontSizeToFitWidth = YES;
    [self addSubview:detailTextLabel];
    
    UILabel *detailValueLabel = [[UILabel alloc] initWithFrame:CGRectMake(detailTextLabel.cy_right+10, detailTextLabel.cy_y, valueMaxWidth, detailSize.height)];
    if (detailValueLabel.height<40.0) {
        detailValueLabel.height = 40;
    } else {
        detailValueLabel.height += 20;
    }
    detailValueLabel.font = font(14);
    detailValueLabel.textColor = Dark_TextColor;
    detailValueLabel.textAlignment = NSTextAlignmentRight;
    detailValueLabel.text = [NSString nullToString:detailDic[@"details"]];
    detailValueLabel.numberOfLines = 0;
    [self addSubview:detailValueLabel];
    
    UIView *line2 = [[UIView alloc] initWithFrame:CGRectMake(15, detailValueLabel.cy_bottom-1, ScreenW-30, 1)];
    line2.backgroundColor = BackgroundColor;
    [self addSubview:line2];
    
    ///车牌号
    UILabel *carNumTextLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, detailValueLabel.cy_bottom, 70, item_height)];
    carNumTextLabel.font = font(14);
    carNumTextLabel.textColor = Light_TextColor;
    carNumTextLabel.text = @"车牌号码";
    carNumTextLabel.adjustsFontSizeToFitWidth = YES;
    [self addSubview:carNumTextLabel];
    
    UILabel *carNumValueLabel = [[UILabel alloc] initWithFrame:CGRectMake(carNumTextLabel.cy_right+10, carNumTextLabel.cy_y, valueMaxWidth, item_height)];
    carNumValueLabel.font = font(14);
    carNumValueLabel.textColor = Dark_TextColor;
    carNumValueLabel.textAlignment = NSTextAlignmentRight;
    carNumValueLabel.text = [NSString nullToString:detailDic[@"numberPlate"]];
    [self addSubview:carNumValueLabel];
    
    UIView *line3 = [[UIView alloc] initWithFrame:CGRectMake(15, carNumValueLabel.cy_bottom-1, ScreenW-30, 1)];
    line3.backgroundColor = BackgroundColor;
    [self addSubview:line3];
    
    //图片区域
    UIView *imgBgView = [[UIView alloc] initWithFrame:CGRectMake(0, carNumValueLabel.cy_bottom, ScreenW, 40 + 75)];
    imgBgView.tag = 150;
    [self addSubview:imgBgView];
    
    UILabel *imgTitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 0, 200, 40)];
    imgTitleLabel.font = font(14);
    imgTitleLabel.textColor = Light_TextColor;
    imgTitleLabel.text = @"相关图片：";
    [imgBgView addSubview:imgTitleLabel];
    
    //图片
    NSArray *imgArr = [[NSString nullToString:detailDic[@"images"]] componentsSeparatedByString:@","];
    
    float width = (ScreenW-60)/4;
    
    for (int i=0; i<imgArr.count; i++) {
        UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(15 + (width+15)*i, 40, width, 75)];
        imageView.userInteractionEnabled = YES;
        setNetImage(imageView, imgArr[i], @"gcy_icon_plaholder");
        [imgBgView addSubview:imageView];
        
        [imageView nyl_addTapGes:^{
            HZPhotoBrowser *browser = [[HZPhotoBrowser alloc] init];
            browser.isFullWidthForLandScape = YES;
            browser.isNeedLandscape = YES;
            browser.currentImageIndex = i;
            browser.imageArray = imgArr;
            [browser show];
        }];
    }
    
    
    UILabel *statusTextLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, imgBgView.cy_bottom, 70, item_height)];
    statusTextLabel.font = font(14);
    statusTextLabel.textColor = Light_TextColor;
    statusTextLabel.text = @"审核状态";
    statusTextLabel.adjustsFontSizeToFitWidth = YES;
    [self addSubview:statusTextLabel];
    
    //维修状态
    _statusLabel = [[UILabel alloc] initWithFrame:CGRectMake(statusTextLabel.cy_right+10, imgBgView.cy_bottom, valueMaxWidth, item_height)];
    _statusLabel.font = font(14);
    _statusLabel.textColor = Dark_TextColor;
    _statusLabel.textAlignment = NSTextAlignmentRight;
    NSInteger status = [detailDic[@"status"] integerValue];
    if (status == 0) {
        _statusLabel.text = @"审核中";
    } else if (status == 1) {
        _statusLabel.text = @"已同意";
    } else if (status == 2) {
        _statusLabel.text = @"已拒绝";
    }
    [self addSubview:_statusLabel];
    
    _bLine = [[UIView alloc] initWithFrame:CGRectMake(0, _statusLabel.cy_bottom, ScreenW, 10)];
    _bLine.backgroundColor = BackgroundColor;
    [self addSubview:_bLine];
    
    
    
    
    if ([detailDic[@"isReportComplete"] integerValue] == 1) {
        [self createDetailView];
        
        /////////////////
        NSArray *arr2 = @[CJStringWithFormat(@"%@", detailDic[@"reportCompleteFee"]),
                          [NSString nullToString:detailDic[@"reportCompleteDetails"]],
        ];
        
        for (int i=0; i<arr2.count; i++) {
            UILabel *textLabel = [self viewWithTag:300 + i];
            textLabel.text = arr2[i];
        }
        
        //图片
        NSArray *detailImgArr = [[NSString nullToString:detailDic[@"reportCompleteImgs"]] componentsSeparatedByString:@","];
        
        UIView *detailImgBgView = [self viewWithTag:200];
        
        for (int i=0; i<detailImgArr.count; i++) {
            UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(15 + (width+10)*i, 40, width, 75)];
            imageView.userInteractionEnabled = YES;
            setNetImage(imageView, detailImgArr[i], @"gcy_icon_plaholder");
            [detailImgBgView addSubview:imageView];
            
            [imageView nyl_addTapGes:^{
                HZPhotoBrowser *browser = [[HZPhotoBrowser alloc] init];
                browser.isFullWidthForLandScape = YES;
                browser.isNeedLandscape = YES;
                browser.currentImageIndex = i;
                browser.imageArray = detailImgArr;
                [browser show];
            }];
        }
    }
}

#pragma mark - 已上报维修信息区域

- (void)createDetailView {
    
    UILabel *detailTitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, _bLine.cy_bottom, 200, 40)];
    detailTitleLabel.font = font(16);
    detailTitleLabel.textColor = Dark_TextColor;
    detailTitleLabel.text = @"维修详情";
    [self addSubview:detailTitleLabel];
    
    NSArray *detailTitlesArr = @[@"维修费用", @"维修详情"];
    
    for (int i=0; i<detailTitlesArr.count; i++) {
        
        UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(0, detailTitleLabel.cy_bottom + 40*i, ScreenW, 40)];
        [self addSubview:bgView];
        
        CGSize textSize = [DCSpeedy dc_calculateTextSizeWithText:detailTitlesArr[i] WithTextFont:14 WithMaxW:1000];
        
        UILabel *textLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 0, textSize.width, bgView.cy_height)];
        textLabel.font = font(14);
        textLabel.textColor = Light_TextColor;
        textLabel.text = detailTitlesArr[i];
        textLabel.adjustsFontSizeToFitWidth = YES;
        [bgView addSubview:textLabel];
        
        UILabel *valueLabel = [[UILabel alloc] initWithFrame:CGRectMake(textLabel.cy_right+10, 0, ScreenW-textSize.width-40, bgView.cy_height)];
        valueLabel.tag = 300 + i;
        valueLabel.font = font(14);
        //        valueLabel.numberOfLines = 2;
        valueLabel.textColor = Dark_TextColor;
        valueLabel.text = @"-";
        valueLabel.textAlignment = NSTextAlignmentRight;
        //        valueLabel.adjustsFontSizeToFitWidth = YES;
        [bgView addSubview:valueLabel];
        
        UIView *line = [[UIView alloc] initWithFrame:CGRectMake(15, 39, ScreenW-30, 1)];
        line.backgroundColor = BackgroundColor;
        [bgView addSubview:line];
    }
    
    //图片区域
    UIView *detailImgBgView = [[UIView alloc] initWithFrame:CGRectMake(0, detailTitleLabel.cy_bottom + detailTitlesArr.count * 40, ScreenW, 40 + 75)];
    detailImgBgView.tag = 200;
    [self addSubview:detailImgBgView];
    
    UILabel *detailImgTitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 0, 200, 40)];
    detailImgTitleLabel.font = font(14);
    detailImgTitleLabel.textColor = Dark_TextColor;
    detailImgTitleLabel.text = @"相关图片：";
    [detailImgBgView addSubview:detailImgTitleLabel];
    
    
    
    UIView *bLine2 = [[UIView alloc] initWithFrame:CGRectMake(0, detailImgBgView.cy_bottom + 10, ScreenW, 10)];
    bLine2.backgroundColor = BackgroundColor;
    [self addSubview:bLine2];
    
    _shenPiTextLabel.cy_y = bLine2.cy_bottom;
    _shenPiTextLabel.hidden = NO;
    
}

@end
